﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class admin_qlproductlang : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        e.Cancel = true;
        Label id = (Label)this.GridView1.Rows[e.NewEditIndex].Cells[0].FindControl("id");
        Label lang = (Label)this.GridView1.Rows[e.NewEditIndex].Cells[1].FindControl("lg");
        Response.Redirect("Default.aspx?page=edproductlang&id=" + id.Text + "&lang=" + lang.Text);
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        e.Cancel = true;
        Label id = (Label)this.GridView1.Rows[e.RowIndex].Cells[0].FindControl("id");
        Label lang = (Label)this.GridView1.Rows[e.RowIndex].Cells[0].FindControl("lg");
        connection con = new connection();
        SqlConnection cn = con.connect();
        //xoa category_lang
        SqlCommand mySqlSelect = new SqlCommand("delete from product_lang where id = @id and lang = @lg", cn);
        mySqlSelect.CommandType = CommandType.Text;

        SqlParameter idt = new SqlParameter("@id", SqlDbType.BigInt);
        idt.Value = Int64.Parse(id.Text);

        SqlParameter lg = new SqlParameter("@id", SqlDbType.NVarChar, 2);
        lg.Value = lang.Text;

        mySqlSelect.Parameters.Add(idt);
        mySqlSelect.Parameters.Add(lg);
        mySqlSelect.ExecuteNonQuery();
        cn.Close();
        SqlDataSource1.DataBind();
        GridView1.DataBind();
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#99ffcc'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;");
        }
    }

    protected void addbt_Click(object sender, EventArgs e)
    {
        try
        {
            connection con = new connection();
            SqlConnection cn = con.connect();
            SqlCommand mySqlSelect = new SqlCommand("insert into product_lang values(@id, @lang, @menu, @title, @add, @invest, @arc)", cn);
            mySqlSelect.CommandType = CommandType.Text;

            SqlParameter lg = new SqlParameter("@lang", SqlDbType.NVarChar, 2);
            lg.Value = lang.SelectedValue;

            SqlParameter id = new SqlParameter("@id", SqlDbType.BigInt);
            id.Value = Request.QueryString["id"];

            SqlParameter me = new SqlParameter("@menu", SqlDbType.NVarChar, 50);
            me.Value = menu.Text;

            SqlParameter tit = new SqlParameter("@title", SqlDbType.NVarChar, 100);
            tit.Value = title.Text;

            SqlParameter address = new SqlParameter("@add", SqlDbType.NVarChar, 100);
            address.Value = add.Text;

            SqlParameter inv = new SqlParameter("@invest", SqlDbType.NVarChar, 50);
            inv.Value = invest.Text;

            SqlParameter arc = new SqlParameter("@arc", SqlDbType.NVarChar, 50);
            arc.Value = archi.Text;

            mySqlSelect.Parameters.Add(lg);
            mySqlSelect.Parameters.Add(id);
            mySqlSelect.Parameters.Add(me);
            mySqlSelect.Parameters.Add(tit);
            mySqlSelect.Parameters.Add(address);
            mySqlSelect.Parameters.Add(inv);
            mySqlSelect.Parameters.Add(arc);
            mySqlSelect.ExecuteNonQuery();
            cn.Close();
            info.Text = "Thêm dữ liệu thành công";
            SqlDataSource1.DataBind();
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            info.Text = "Dữ liệu này bạn đã nhập. Xin vui lòng chỉnh sửa";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?page=qlproduct");
    }
}